package com.cuiweiyou.uiautomator20;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

/**
 * www.gaohaiyan.com
 */
public class UtilFile {
    private UtilFile() {
    }

    public static void appendText(String fileName, String content) {
        FileWriter writer = null;
        try {
            writer = new FileWriter(fileName, true); // 打开写文件器。true-追加
            writer.write(content);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (null != writer) {
                try {
                    writer.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static void initSourcePath() {
        String dbPath = Constant.SOURCEPATH;
        File pathFile = new File(dbPath);

        if (!pathFile.exists()) {
            pathFile.mkdirs();
            UtilLogs.saveLog("初始化资源路径：" + dbPath);
        }
    }

    public static File getCommGimmickFile() {
        String gimmickPath = Constant.SOURCEPATH + "/gimmick_comm.txt";
        UtilLogs.saveLog("comm对话话术：" + gimmickPath);
        return new File(gimmickPath);
    }

    public static File getHelloGimmickFile() {
        String gimmickPath = Constant.SOURCEPATH + "/gimmick_hello.txt";
        UtilLogs.saveLog("hello问好话术：" + gimmickPath);
        return new File(gimmickPath);
    }

    public static File getWordFile() {
        String wordPath = Constant.SOURCEPATH + "/word.txt";
        UtilLogs.saveLog("分词文件：" + wordPath);
        return new File(wordPath);
    }

    public static File getDeviceFile() {
        String devicePath = Constant.SOURCEPATH + "/device.txt";
        UtilLogs.saveLog("手机适配文件：" + devicePath);
        return new File(devicePath);
    }
}